import { Request } from "express";
import RequestProcess from "../RequestProcess/RequestProcess";
import RegisterRequestProcess from "../RequestProcess/RegisterRequestProcess";
import LogInRequestProcess from "../RequestProcess/LogInRequestProcess";
import SendMessageRequestProcess from "../RequestProcess/SendMessageRequestProcess";
import GetMessageRequestProcess from "../RequestProcess/GetMessageRequestProcess";
import CreateGroupRequestProcess from "../RequestProcess/CreateGroupRequestProcess"
import EnterGroupRequestProcess from "../RequestProcess/EnterGroupRequestProcess"
import BuildFriendOperation from "../operator/BuildFriendOperation";
import BuildFriendRequestProcess from "../RequestProcess/BuildFriendRequestProcess";
import GetFriendAndGroupRequestOperation from "../RequestProcess/GetFriendAndGroupRequestOperation";
import GetUserOrGroupNameOperation from "../operator/GetUserOrGroupNameOperation";
import GetNameByIdRequestProcess from "../RequestProcess/GetNameByIdRequestProcess";

export enum HttpRequestEvenType {
    REGISTER,
    LOGIN,
    SEND,
    GET,
    CreateGroup,
    EnterGroup,
    BuildFriend,
    GetInfo,
    GetName
}

export class HttpRequestEven {
    private type: HttpRequestEvenType;
    private req !: Request;
    private RequestProcess !: RequestProcess;
    private result !: Object;

    constructor(req: Request, type: HttpRequestEvenType) {
        this.type = type;
        this.req = req;
    }

    public createRequestProcess() {
        switch (this.type) {
            case HttpRequestEvenType.REGISTER:
                this.RequestProcess = new RegisterRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.LOGIN:
                this.RequestProcess = new LogInRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.SEND:
                this.RequestProcess = new SendMessageRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.GET:
                this.RequestProcess = new GetMessageRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.CreateGroup:
                this.RequestProcess = new CreateGroupRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.EnterGroup:
                this.RequestProcess = new EnterGroupRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.BuildFriend:
                this.RequestProcess = new BuildFriendRequestProcess(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.GetInfo:
                this.RequestProcess = new GetFriendAndGroupRequestOperation(this.req);
                return this.RequestProcess;
            case HttpRequestEvenType.GetName:
                this.RequestProcess = new GetNameByIdRequestProcess(this.req);
                return this.RequestProcess;
            default:
                break;
        }
    }

    public async getResult() {
        return await this.RequestProcess.process().then(
            (result) => {
                return result;
            }
        )
    }
}
